<template>
  <div>
    <router-link  tag="div" to="/" class="header-abs" v-show="showAbs">
      <span class="iconfont header-abs-back">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      景点选择
    </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    // 全局组件的解绑
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    // 页面即将被隐藏/替换
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        const opacity = (top / 140) > 1 ? 1 : top / 140
        this.opacityStyle = {
          opacity
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  }
}
</script>
<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-abs
    position: absolute
    left: .2 rem
    top: .2 rem
    width: .8 rem
    height: .8 rem
    line-height: .8 rem
    border-radius: .4rem
    z-index: 99
    background: rgba(0, 0, 0, .8)
    .header-abs-back
      color: #fff
  .header-fixed
    overflow: hidden
    height: $headerHeight
    line-height: $headerHeight
    text-align: center
    color: #fff
    background: $bgcolor
    position: fixed
    top: 0
    left: 0
    right: 0
</style>
